﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using System.ComponentModel.Composition;
using EIA.SLClient.PlatManage.Infrastructure;

namespace EIA.SLClient.PlatManage.PMMgr
{
    [Export]
    [ViewSortHint("02")]
    public partial class PMMgrNavigationItemView : UserControl, IPartImportsSatisfiedNotification
    {
        private static Uri pmMgrNavigationViewUri = new Uri(typeof(PMMgrNavigationView).FullName, UriKind.Relative);

        [Import]
        public IRegionManager regionManager;

		public PMMgrNavigationItemView()
		{
			// 为初始化变量所必需
			InitializeComponent();
		}

        void IPartImportsSatisfiedNotification.OnImportsSatisfied()
        {
            IRegion SubNavigationRegion = this.regionManager.Regions[RegionNames.SubNavigationRegion];
            if (SubNavigationRegion != null && SubNavigationRegion.NavigationService != null)
            {
                SubNavigationRegion.NavigationService.Navigated += this.SubNavigationRegion_Navigated;
            }
        }

        public void SubNavigationRegion_Navigated(object sender, RegionNavigationEventArgs e)
        {
            this.UpdateNavigationButtonState(e.Uri);
        }

        private void UpdateNavigationButtonState(Uri uri)
        {
            this.NavigateToPMMgrRadioButton.IsChecked = (uri == pmMgrNavigationViewUri);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.regionManager.RequestNavigate(RegionNames.SubNavigationRegion, pmMgrNavigationViewUri);
        }
    }
}